home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00073_Script_PaginasGenerico < prev    next >
Text File  |  1999-03-19  |  14KB  |  484 lines

  1. property sprIndicadorScroll -- Sprite com botao de scroll
  2. property estado -- 0 para generico, 1 para alfabetico
  3.  
  4. property spr
  5. property memMe -- Membro que contem lista
  6. property intPalavraClicada -- Palavra digitada
  7.  
  8. -- Palavras selecionadas (clicadas)
  9. property intIndicePaginas, intIndiceMidias
  10.  
  11.  
  12. -- Ataualizacao da lista
  13. property bBuscando
  14. property intScroll, intLinhas
  15. property strLista, intNovasLinhas
  16. property timeUltimaAtualizacao
  17.  
  18. -- Descricao da Behavior
  19. on getBehaviorDescription
  20.   return "Gerencia lista de paginas"
  21. end
  22.  
  23. on getPropertyDescriptionList
  24.   set p_list = [ ¼
  25.   #sprIndicadorScroll: [ #comment:   "Sprite do indicador de scroll", ¼
  26.   #format:   #integer, ¼
  27.   #default:    "" ] ¼
  28.   ]
  29.   return p_list
  30. end
  31.  
  32. -- Inicializacao do sprite
  33. on beginSprite me
  34.   set spr = the spriteNum of me
  35.   put the member of sprite spr into memMe
  36.   put 0 into intScroll
  37.   put 0 into intLinhas
  38.   set the text of member memMe to ""
  39.   set strLista to ""
  40.   set intNovasLinhas to 0
  41.   set bBuscando to false
  42.   set estado = 0
  43.   set intIndicePaginas = []
  44.   set intIndiceMidias = []
  45.   set intPalavraClicada = 0
  46.   set the foreColor of member memMe to ¼
  47.       (the backColor of member "FundoPreto")
  48.   set the fontSize of member memMe to¼
  49.       the fontSize of member "TipoLetra"
  50.   set the font of member memMe to¼
  51.       the font of member "TipoLetra"
  52. end
  53.  
  54. -- Mensagens de scroll
  55. on scrollingUp me
  56.   if intScroll > 0 then 
  57.     scrollByLine member memMe, -1
  58.     put intScroll - 1 into intScroll
  59.     sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  60.   end if
  61.   updateStage
  62.   set tmp = the timer + 20
  63.   repeat while the mouseDown
  64.     if intScroll > 0 and the timer - tmp > 6 then 
  65.       scrollByLine member memMe, -1
  66.       put intScroll - 1 into intScroll
  67.       sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  68.       updateStage
  69.       set tmp = the timer
  70.     end if
  71.     -- Faz idle sprite
  72.     global gMustUpdate
  73.     set gMustUpdate = false
  74.     sendAllSprites(#idleSprite)
  75.     if gMustUpdate then updateStage
  76.   end repeat
  77. end 
  78.  
  79. on scrollingDown me
  80.   if intLinhas > 5 and intScroll < intLinhas - 1 then
  81.     scrollByLine member memMe, +1
  82.     put 1 +  intScroll into intScroll
  83.     sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  84.     updateStage
  85.   end if
  86.   set tmp = the timer + 20
  87.   repeat while the mouseDown
  88.     if intLinhas > 5 and intScroll < intLinhas - 1 and the timer - tmp > 6 then
  89.       scrollByLine member memMe, +1
  90.       put 1 +  intScroll into intScroll
  91.       sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  92.       updateStage
  93.       set tmp = the timer
  94.     end if
  95.     -- Faz idle sprite
  96.     global gMustUpdate
  97.     set gMustUpdate = false
  98.     sendAllSprites(#idleSprite)
  99.     if gMustUpdate then updateStage
  100.   end repeat
  101.   
  102. end
  103.  
  104. on scrollPaginaCima
  105.   if  intLinhas <= 5 then return
  106.   put intScroll-5 into tmp
  107.   if tmp < 0 then put 0 into tmp
  108.   scrollByLine member memMe, tmp - intScroll
  109.   put tmp into intScroll
  110.   sendSprite(sprIndicadorScroll, #move, intScroll*10000/(intLinhas-1))
  111.   updateStage
  112. end
  113.  
  114. on scrollPaginaBaixo
  115.   if  intLinhas <= 5 then return
  116.   put intScroll+5 into tmp
  117.   if tmp > intLinhas - 1 then put intLinhas - 1 into tmp
  118.   scrollByLine member memMe, tmp - intScroll
  119.   put tmp into intScroll
  120.   sendSprite(sprIndicadorScroll, #move, intScroll*10000/(intLinhas-1))
  121.   updateStage
  122. end  
  123.  
  124. on scrollArraste me, posicao
  125.   if intLinhas <= 5 then return
  126.   put posicao * (intLinhas - 1) / 10000 into tmp
  127.   scrollByLine member memMe, tmp - intScroll
  128.   put tmp into intScroll
  129. end
  130.  
  131. on scrollArrasteFim me
  132.   if intLinhas <= 5 then 
  133.     sendSprite(sprIndicadorScroll, #move, 0)
  134.     updateStage
  135.   end if
  136. end
  137.  
  138. on scrollLinha me, linha
  139.   scrollByLine member memMe, linha - intScroll
  140.   set intScroll = linha
  141.   sendSprite(sprIndicadorScroll, #move, intScroll*10000/(intLinhas-1))
  142.   updateStage
  143. end
  144.  
  145.  
  146. -------------------------------------------------------------------
  147. -------------------------------------------------------------------
  148. -------------------------------------------------------------------
  149. -- Zera lista
  150. on zera me
  151.   put 0 into intScroll
  152.   put 0 into intLinhas
  153.   set strLista to ""
  154.   set intNovasLinhas to 0
  155.   set bBuscando to false
  156.   sendSprite(sprIndicadorScroll, #move, 0)
  157.   set intPalavraClicada = 0
  158.   set intIndicePaginas = []
  159.   set intIndiceMidias = []
  160.   set the text of field memMe to ""
  161.   set the foreColor of member memMe to ¼
  162.       (the backColor of member "FundoPreto")
  163.   --  set the fontSize of member memMe to¼
  164. --      the fontSize of member "TipoLetra"
  165.   --  set the font of member memMe to¼
  166. --      the font of member "TipoLetra"
  167.   
  168. end
  169.  
  170. -- Prenche lista com paginas onde ocorrem a palavra de indice <pal>
  171. on preenche me, pal
  172.   global gRefs, gArqs
  173.   
  174.   
  175.   set intPalavraClicada = 0
  176.   
  177.   --  put "PaginasGenerico: preenche # pal=" & pal
  178.   -- Limpa listas
  179.   put 0 into intScroll
  180.   put 0 into intLinhas
  181.   
  182.   cursor 4
  183.   updateStage
  184.   
  185.   put "" into strLista
  186.   set intNovasLinhas to 0
  187.   put [] into intIndicePaginas
  188.   put [] into intIndiceMidias
  189.   put false into bBuscando
  190.   
  191.   -- Faz busca de referencias 
  192.   mSetCriteria(gRefs,"palNum", "=", pal)
  193.   mSelect(gRefs)
  194.   put mSelectCount(gRefs) into counter
  195.   put counter into tmp
  196.   --  put "PaginasGenerico: preenche # matches=" & counter
  197.   
  198.   -- Primeiro le referencias
  199.   put [] into lista
  200.   put [] into listaMidias
  201.   repeat while tmp > 0
  202.     set an = mGetField(gRefs,"arqNum")
  203.     if an = 8 then
  204.       if getPos(lista,7) = 0 then
  205.         add lista,7
  206.         add listaMidias, mGetField(gRefs,"mediaNum")
  207.       else
  208.         set counter = counter - 1
  209.       end if
  210.     else
  211.       add lista,an
  212.       add listaMidias, mGetField(gRefs,"mediaNum")
  213.     end if
  214.     mGoNext(gRefs)
  215.     put tmp-1 into tmp
  216.   end repeat
  217.   --  put "PaginasGenerico: preenche # indices=" & lista
  218.   
  219.   -- Le titulos dos arquivos
  220.   mSetIndex(gArqs,"arqNdx")
  221.   put 1 into idx
  222.   repeat while counter > 0
  223.     -- Pega indice do arquivo/pagina
  224.     put getAt(lista,idx) into ai
  225.     put getAt(listaMidias,idx) into midias
  226.     put 1 into mi
  227.     put idx+1 into idx
  228.     -- Le titulo do arquivo
  229.     mSetCriteria(gArqs, "arqNum", "=", ai)
  230.     mSelect(gArqs)
  231.     put "- " & mGetField(gArqs,"arquivo") into titulo
  232.     -- Tira espaco no final do titulo
  233.     set i = length(titulo)
  234.     repeat while i > 0 and char i of titulo = SPACE
  235.       set i = i - 1
  236.     end repeat
  237.     set titulo = char 1 to i of titulo
  238.     -- Monta lista de indices
  239.     put the number of words in titulo into tmp
  240.     repeat while tmp > 0
  241.       add intIndicePaginas, ai
  242.       add intIndiceMidias, 1
  243.       put tmp-1 into tmp
  244.     end repeat    
  245.     -- Atualiza lista
  246.     if (strLista <> "") then put RETURN after strLista
  247.     put titulo after strLista
  248.     if (midias <> 1) then
  249.       if (midias > 8) then
  250.         put midias - 8 into midias
  251.         add intIndicePaginas, ai
  252.         add intIndiceMidias, 8
  253.         put " [Cinema]" after strLista
  254.       end if
  255.       if (midias > 4) then
  256.         put midias - 4 into midias
  257.         add intIndicePaginas, ai
  258.         add intIndiceMidias, 4
  259.         put " [TV]" after strLista
  260.       end if
  261.       if (midias > 2) then
  262.         put midias - 2 into midias
  263.         add intIndicePaginas, ai
  264.         add intIndiceMidias, 2
  265.         put " [HQ]" after strLista
  266.       end if      
  267.     end if
  268.     
  269.     -- Proxima pagina
  270.     put counter - 1 into counter
  271.   end repeat
  272.   
  273.   -- Reseta lista de palavras
  274.   global eMac
  275.   if eMac then
  276.     trocaTexto memMe, strLista, (the backColor of member "FundoPreto"), ¼
  277.                 "PaginasGenerico", "PaginasGenericoBack"
  278.   else
  279.     set the text of field memMe to strLista 
  280.     set the foreColor of member memMe to ¼
  281.       (the backColor of member "FundoPreto")
  282.   end if
  283.   updateStage
  284.   
  285.   put 0 into intScroll
  286.   put the lineCount of member memMe into intLinhas
  287.   sendSprite(sprIndicadorScroll, #move, 0)  
  288.   
  289.   -- Atualiza "Stage"
  290.   cursor -1
  291.   updateStage
  292. end
  293.  
  294.  
  295. -- Seleciona pagina e vai para respectiva
  296. on mouseUp me
  297.   put the mouseWord into mw
  298.   if mw < 1 then return
  299.   set tmp = count(intIndicePaginas)
  300.   if tmp = 0 then set tmp = (the number of items in field "ListaAlfabeticaRef") - 1
  301.   if mw > tmp then return
  302.   if count(intIndicePaginas) = 0 then
  303.     set tmp2 = 1
  304.     set tmp1 = Integer(item mw of field "ListaAlfabeticaRef")
  305.   else
  306.     put getAt(intIndicePaginas,mw) into tmp1
  307.     put getAt(intIndiceMidias,mw) into tmp2
  308.   end if
  309.   if the doubleClick then
  310.     puppetSound 2, "CliqueVaiVolta"
  311.     vaiPagina tmp1, true
  312.   else
  313.     if intPalavraClicada <> 0 then
  314.       if the estado of sprite 97 < 2 then
  315.         set cor = (the backColor of member "FundoPreto") -- black
  316.       else 
  317.         set cor = (the backColor of member "FundoBranco") -- white
  318.       end if
  319.       if the platform contains "Mac" then
  320.         set the foreColor of member memMe to cor
  321.       else
  322.         pinta me, intPalavraClicada, cor
  323.       end if
  324.     end if
  325.     pinta me, mw, ¼
  326.             (the backColor of member "FundoAzul")
  327.     set intPalavraClicada = mw
  328.     -- Marca linha
  329.   end if
  330. end 
  331.  
  332. -- Seleciona novo membro
  333. on setMembro me, strMembro
  334.   set the member of sprite spr to member strMembro
  335.   set memMe to the member of sprite spr
  336.   if the estado of sprite 97 < 2 then
  337.     set cor = (the backColor of member "FundoPreto") -- black
  338.   else 
  339.     set cor = (the backColor of member "FundoBranco") -- white
  340.   end if
  341.   set the foreColor of member memMe to cor
  342.   --  set the fontSize of member memMe to¼
  343. --      the fontSize of member "TipoLetra"
  344.   --  set the font of member memMe to¼
  345. --      the font of member "TipoLetra"
  346.   
  347. end
  348.  
  349. -- Pinta palavras de indice de uma determinada cor
  350. on pinta me, pal, cor
  351.   put count(intIndicePaginas) into max
  352.   set alfa = false
  353.   if max = 0 then 
  354.     set max = the number of items in field "ListaAlfabeticaRef"
  355.     set arq = Integer(item pal of field "ListaAlfabeticaRef")
  356.     set alfa = true
  357.   else
  358.     put getAt(intIndicePaginas, pal) into arq
  359.   end if
  360.   --  put "PalavrasGenerico: pinta # pal=" & pal & ", idx=" & tmp &¼
  361.   --      ", cor=" & cor
  362.   set tmp = pal
  363.   -- Pinta palavras posteriores de mesmo indice (arq)
  364.   
  365.   if alfa then set x = Integer(item pal of field "ListaAlfabeticaRef")
  366.   else set x = getAt(intIndicePaginas,pal)
  367.   
  368.   repeat while x = arq 
  369.     set the forecolor of word pal of member memMe to cor
  370.     put pal + 1 into pal
  371.     if pal > max then exit repeat
  372.     if alfa then set x = Integer(item pal of field "ListaAlfabeticaRef")
  373.     else set x = getAt(intIndicePaginas,pal)
  374.   end repeat
  375.   
  376.   set pal = tmp - 1
  377.   -- Pinta palavras anteriores de mesmo indice
  378.   repeat while pal >= 1
  379.     if alfa then set x = Integer(item pal of field "ListaAlfabeticaRef")
  380.     else set x = getAt(intIndicePaginas,pal)
  381.     if x = arq then
  382.       set the forecolor of word pal of member memMe to cor
  383.       set pal = pal - 1
  384.     else
  385.       set pal = 0
  386.     end if
  387.   end repeat
  388. end
  389.  
  390.  
  391. -- Lista todas paginas em ordem alfabetica
  392. on listaTodos me
  393.   cursor 4
  394.   updateStage
  395.   
  396.   -- Reseta lista de palavras
  397.   set the foreColor of member memMe to ¼
  398.       (the backColor of member "FundoPreto")
  399.   put the lineCount of member memMe into intLinhas
  400.   set the scrollTop of member memMe to 0
  401.   put 0 into intScroll
  402.   sendSprite(sprIndicadorScroll, #move, 0)  
  403.   set intIndicePaginas = []
  404.   
  405.   cursor -1
  406. end
  407.  
  408.  
  409. -- Lista paginas selecionadas
  410. on listaSelecionados me
  411.   global gArqs
  412.   
  413.   
  414.   set intPalavraClicada = 0
  415.   
  416.   cursor 4
  417.   updateStage
  418.   
  419.   -- Lista dos selecionados
  420.   global gPagSel, gPagArraste
  421.   set counter =  count(gPagSel)
  422.   
  423.   -- Prepara lista
  424.   put 1 into idx
  425.   put [] into intIndicePaginas
  426.   put [] into intIndiceMidias
  427.   set strLista = ""
  428.   
  429.   repeat while counter > 0
  430.     -- Le registro
  431.     set ai = getAt(gPagSel,idx)
  432.     mSetCriteria(gArqs,"arqNum", "=", ai)
  433.     mSelect(gArqs)
  434.     set titulo = "- " & mGetField(gArqs,"arquivo")
  435.     -- Tira espaco no final do titulo
  436.     set i = length(titulo)
  437.     repeat while i > 0 and char i of titulo = SPACE
  438.       set i = i - 1
  439.     end repeat
  440.     set titulo = char 1 to i of titulo
  441.     
  442.     -- Monta lista de indices
  443.     put the number of words in titulo into tmp
  444.     repeat while tmp > 0
  445.       add intIndicePaginas, ai
  446.       add intIndiceMidias, 1
  447.       put tmp-1 into tmp
  448.     end repeat   
  449.     
  450.     -- Atualiza lista
  451.     if (strLista <> "") then put RETURN after strLista
  452.     put titulo after strLista
  453.     
  454.     -- Proxima pagina
  455.     put counter - 1 into counter
  456.     set idx = idx + 1
  457.   end repeat
  458.   
  459.   -- Reseta lista de palavras
  460.   global eMac
  461.   if eMac then
  462.     trocaTexto memMe, strLista, (the backColor of member "FundoBranco"), ¼
  463.                 "PaginasSelecionadas", "PaginasSelecionadasBack"
  464.   else
  465.     set the foreColor of member memMe to ¼
  466.       (the backColor of member "FundoBranco")
  467.     set the text of member memMe to strLista
  468.     set the foreColor of member memMe to ¼
  469.       (the backColor of member "FundoBranco")
  470.     set the scrollTop of member memMe to 0
  471.   end if
  472.   
  473.   put 0 into intScroll
  474.   sendSprite(sprIndicadorScroll, #move, 0)  
  475.   put the lineCount of member memMe into intLinhas
  476.   
  477.   cursor -1
  478. end
  479.  
  480. -- Adiciona 
  481. on addSelecionados me
  482.   global gPagSel, gPagArraste
  483.   
  484. end